package com.mjlf.mjatis.mapper;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mjlf.mjatis.config.Configuration;
import com.mjlf.mjatis.util.Json2Entity;
import com.sun.org.apache.regexp.internal.RE;
import lombok.extern.java.Log;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName MapperMethodUtil
 * @Author mjlft
 * @Date 2020/5/31 16:35
 * @Version 1.0
 * @Description MeapperMethod工具类
 */

@Log
public final class MapperMethodUtil {

    public static Set<MapperMethod> parse(JSONArray mqlArray) throws IllegalAccessException, InstantiationException {
        if(mqlArray != null){
            Set<MapperMethod> mapperMethods = new HashSet<>((int)(mqlArray.size() / 0.75) + 1);
            for(int i = 0; i < mqlArray.size(); i ++){
                MapperMethod mapperMethod = parse(mqlArray.getJSONObject(i));
                if(mapperMethod != null){
                    mapperMethods.add(mapperMethod);
                }
            }
            return mapperMethods;
        }
        return null;
    }

    public static MapperMethod parse(JSONObject mqlJson) throws InstantiationException, IllegalAccessException {
        if(mqlJson != null){
            MapperMethod mapperMethod = Json2Entity.getEntity(mqlJson, MapperMethod.class);
            return mapperMethod;
        }
        return null;
    }

    public static void parseResultType(MapperMethod mapperMethod, Configuration configuration){
        String resultType = mapperMethod.getResultType();
        //处理结果集映射
    }
}
